function clamp(v,min,max)
    if(max >= min) then
        if(v < min) then
        v= min
        elseif(v > max) then
        v = max
        end
    else
        v = 0
    end

    return v
end

function lerpFloat(a,b,t)
    t=clamp(t,0,1)
    return a * (1-t) + b * t
end

function lerpVec2(v1,v2,t)
    t = clamp(t,0,1)
    local tmp = {}
    tmp.x = lerpFloat(v1.x,v2.x,t)
    tmp.y = lerpFloat(v1.y,v2.y,t)
    return tmp
end
  
  --[[t=0,res=a
      t=0.5,res=b
      t=1,res = a
      ]]--
function pingpongLerp(a,b,t)
    t = clamp(t,0,1)
    if(t <= 0.5) then
        return lerpFloat(a,b,2 * t)
    else
        return lerpFloat(a,b,-2 * t + 2)
    end
end
